package lodsve.test.mongodb.service;

import lodsve.mongodb.connection.MongoSourceProvider;
import lodsve.test.mongodb.domain.Demo;
import lodsve.test.mongodb.domain.Test;
import lodsve.test.mongodb.repository.DemoRepository;
import lodsve.test.mongodb.repository.TestRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * .
 *
 * @author sunhao(sunhao.java @ gmail.com)
 * @version 1.0 2017/12/7 16:00
 */
@Service
public class DemoService {
    @Autowired
    private DemoRepository demoRepository;
    @Autowired
    private TestRepository testRepository;

    @MongoSourceProvider("test")
    public void save1(Test demo) {
        testRepository.save(demo);
    }

    @MongoSourceProvider("test")
    public Test get1(Long id) {
        return testRepository.findById(id);
    }

    @MongoSourceProvider("test")
    public List<Test> list1() {
        return testRepository.findAll();
    }

    @MongoSourceProvider("demo")
    public void save2(Demo demo) {
        demoRepository.save(demo);
    }

    @MongoSourceProvider("demo")
    public Demo get2(Long id) {
        return demoRepository.findById(id);
    }

    @MongoSourceProvider("demo")
    public List<Demo> list2() {
        return demoRepository.findAll();
    }
}
